import store from '@/store';
import { DictData } from '@/types/dictData.model';

export const dictUserStore = defineStore('dict', () => {
  const dict = ref<
    Array<{
      key: string;
      value: DictData[];
    }>
  >([]);


  const getDict=(_key: string) =>{
    if (_key == null && _key == '') {
      return null;
    }
    try {
      for (let i = 0; i < dict.value.length; i++) {
        if (dict.value[i].key == _key) {
          return dict.value[i].value;
        }
      }
    } catch (e) {
      return null;
    }
    return null;

  }
  const setDict=(_key: string, _value: DictData[]) =>{
    if (_key !== null && _key !== '') {
      dict.value.push({
        key: _key,
        value: _value
      });
    }
  }
  const reset=()=>{
    dict.value = [];
  }
  return {
    dict,
    getDict,
    setDict,
    reset
  };



},{unistorage: {key: 'dictDatas',paths: ['dict'] }})

export default dictUserStore;

